<!-- 库区设置 - 综合表单页面 -->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />

    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog" :title="dialogTitle" v-bind="dialog" @afterSubmitSuccess="submitAfter">
    </ex_super_dialog_form>

  </div>
</template>
<script>

import superTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';
import emitOnFunction from '@/mixin/emit-on-function';
const emitKey = 'wms>stock_lock_rule'
export default {
  title: '库存锁定规则',
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: {},
  data() {
    return {
      selection: [],

      option: {
        search: {
          model: [
            { key: "ruleName", label: "规则名称", type: 'select', enum: 'StockLockRuleEnum', },
            { key: "ruleCode", label: "规则编码", },
            { key: "status", label: "label_status", type: 'select', enum: 'IsAvailableStatusEnum', },
          ],
        },
        action: [
          {
            label: '新增锁定规则', attrs: { icon: "el-icon-plus" }, click: () => {
              this.dialogTitle = this.$tt('新增锁定规则')
              this['$refs']['formDialog'].show()
            }
          },
        ],

        table: {
          url: "/wms-api/stock/StockLockRuleRpc/selectListPage.json",
          model: this.init_table_model(),
        },
      },

      dialogTitle: '',
      dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/wms-api/stock/StockLockRuleRpc/saveUpdate.json',
        detailUrl: '/wms-api/stock/StockLockRuleRpc/detail.json',

        form: {
          default: {
            priority: 1,
          },
          itemClass: "form_item_default",
          inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          model: [
            { header: "label_base_info", },
            { key: 'ruleCode', label: '规则编码', if: (data) => data.ruleCode, attrs: { disabled: true, maxlength: 30, 'show-word-limit': true } },
            { key: 'ruleName', label: '规则名称', type: 'select', enum: 'StockLockRuleEnum', },
            {
              key: 'priority', label: 'label_priority', type: 'input-number',
              attrs: {
                'step-strictly': true, step: 1, min: 1,
              }
            },
            { key: 'remark', label: '备注', attrs: { maxlength: 50, 'show-word-limit': true } },

          ],
          rules: {
            'ruleName': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
            'priority': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },

            'remark': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],

          },
        }
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },
        {
          type: 'expandDesc', 'width': 100,
          expandDesc: {
            ...this.$defaultDescAttrs,
            model: [],
          },
        },
        {
          key: 'ruleCode', label: '规则编码', 'min-width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => v ? v.split(',').map(it => this.$enumShow(it, "WavePlanRuleEnum")).join(',') : '',
        },



        {
          key: 'ruleName', label: '规则名称', 'min-width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "StockLockRuleEnum")

        },
        { key: 'priority', label: 'label_priority', 'width': 100, },
        { key: 'remark', label: '备注', 'width': 160, 'show-overflow-tooltip': true, },
        {
          key: 'status', label: 'label_status', 'width': 130, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "IsAvailableStatusEnum")
        },

        { key: 'creator', label: 'label_create_user', 'width': 100, keyShow: "expandDesc", 'show-overflow-tooltip': true, },
        { key: 'gmtCreate', label: 'label_create_time', 'width': 130, keyShow: "expandDesc", 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'modifier', label: 'label_update_user', 'width': 100, keyShow: "expandDesc", 'show-overflow-tooltip': true, },
        { key: 'gmtModify', label: 'label_update_time', 'width': 130, keyShow: "expandDesc", 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$dateFormat(v) },
        {
          type: 'operate', width: 210, operate: [
            {
              label: 'label_edit', click: (row) => {
                this.dialogTitle = this.$tt('编辑锁定规则')
                this['$refs']['formDialog'].show({ "id": row["id"] })
              }
            },
            {
              label: "IsAvailableStatusEnum__ENABLE", type: 'confirm-button', url: '/wms-api/stock/StockLockRuleRpc/updateStatus.json', message: 'label_sure_to_enable_this',
              if: row => !row.status || row.status == 'DISABLED',
              buttonClass: "button_text_success", confirmButtonType: 'success',
              params: (row) => { return { id: row.id, status: 'ENABLE' } }, done: ['reload', 'tip']
            },
            {
              label: "IsAvailableStatusEnum__DISABLED", type: 'confirm-button', url: '/wms-api/stock/StockLockRuleRpc/updateStatus.json', message: 'label_sure_to_disable_this',
              if: row => row.status == 'ENABLE',
              buttonClass: "button_text_danger", confirmButtonType: 'danger',
              params: (row) => { return { id: row.id, status: 'DISABLED' } }, done: ['reload', 'tip']
            }
          ]
        },
      ]
    },
    submitAfter() {
      this.reload()
    },

  }
};

</script>
<style></style>
